﻿using System.Collections.Generic;
using System.Linq;

namespace Common.EF.Structs
{
    public static class EntityConfigManager
    {
        private static List<EntityConfig> entityConfigs = new List<EntityConfig>();

        public static List<EntityConfig> EntityConfigs
        {
            get { return entityConfigs; }
        }

        public static EntityConfig GetEntityConfigByName(string name)
        {
            return EntityConfigs.FirstOrDefault(t => string.Compare(t.Name, name, true) == 0);
        }

        public static void AddEntityConfig(EntityConfig entityConfig)
        {
            if (string.IsNullOrEmpty(entityConfig.Name))
            {
                return;
            }

            var old = EntityConfigs.FirstOrDefault(t => string.Compare(t.Name, entityConfig.Name, true) == 0);
            if (old != null)
            {
                EntityConfigs.Remove(old);
            }

            EntityConfigs.Add(entityConfig);
        }
    }
}
